package com.ms.game.slot.base.table;

import java.util.ArrayList;
import java.util.HashMap;

import com.ms.service.error.ErrorCode;

public class DMBasicTableUserInfo<T, T2>{
	
	private int maxusers = 1;
	
	/**
	 * 玩家列表<br>
	 * key: player id<br>
	 * value: custom user info class
	 */
	private HashMap<String,T> users = new HashMap<String,T>();
	
	private T2 option;
	
	public T2 getOption()
	{
		return option;
	}
	
	public void setOption(T2 op)
	{
		this.option = op;
	}
	
	/**
	 * 設定每館最高上線人數
	 * @param max
	 */
	public void setMaxUser(int max)
	{
		maxusers = max;
	}
	
	/**
	 * 讀取玩家
	 * @param guid
	 * @return
	 */
	public T getUser(String guid)
	{
		if(users.containsKey(guid))
		{
			return users.get(guid);
		}
		
		return null;
	}
	
	/**
	 * 讀取玩家列表
	 * @return
	 */
	public ArrayList<T> getUserList()
	{
		if(users.size()==0)
		{
			return new ArrayList<T>();
		}
		
		return new ArrayList<T>(users.values());
	}
	
	/**
	 * 移除玩家
	 * @param guid
	 * @return
	 */
	public T removeUser(String guid)
	{
		if(!users.containsKey(guid))
		{
			return null;
		}
		
		return users.remove(guid);
	}
	
	/**
	 * 新增玩家
	 * @param data
	 */
	public int  putUser(T data)
	{
		if(users.size() == this.maxusers)
		{
			return ErrorCode.SEAT_IS_FULL;
		}
		
		
		DMBasicTableUser ur = (DMBasicTableUser) data;
		if(users.containsKey(ur.getGuid()))
		{
			return ErrorCode.SEAT_USER_EXISTS;
		}
		users.put(ur.getGuid(), data);
		return ErrorCode.SUCCESS;
	}
	
	public int getSize()
	{
		return users.size();
	}
	
	/**
	 * 設定user 驗證狀態
	 * @param guid
	 * @param isverify
	 */
	public void setUserVerify(String guid , boolean isverify)
	{
		if(!users.containsKey(guid))
		{
			return;
		}
		
		DMBasicTableUser ur = (DMBasicTableUser) users.get(guid);
		ur.setVerify(isverify);
	}
}
 